﻿function CreateTable(result) {
    var tableHTML = '<ul class="display-list list-blog-entry" id="list-blog-entry">';
    for (var i = 0; i < result.length; i++) {
        var dateTime = utcToDate(result[i].CreateDate);
        tableHTML += '<li>';
        tableHTML += '<a href="#" class="preloading-light img-border" title=""><img src="images/pix/logo4.jpg" alt=""></a>';
        tableHTML += '<div class="blog-entry-content">';
        tableHTML += '<h2><a href="../HTML/about.html?newsCode=' + result[i].NewsCode + '" class="first-word">' + result[i].NewsName + '</a></h2>';
        tableHTML += '<div class="posts-info">';
        tableHTML += '<span class="date" title="">' + dateTime + '</span>';
        tableHTML += '<span class="user">' + result[i].Creator + '</span>';
        //tableHTML += '<span class="category"><a href="#">in Tutorial</a></span>';
        tableHTML += '</div>';
        tableHTML += '<p>' + result[i].NewsDesc + '</p>';
        tableHTML += '<a class="read-more" href="../HTML/about.html?newsCode=' + result[i].NewsCode + '" title="更多...">查看全文...</a>';
        tableHTML += '</div>';
        tableHTML += '</li>';
    }
    tableHTML += ' </ul>';
    return tableHTML;
}

function CreatePagination(result, pageIndex, loc) {
    var pageHtml = '';
    var pageCount = result.total / 2;
    var count = 0;
    var index = pageIndex;
    var perv = pageIndex - 1;
    var next = pageIndex + 1;
    if (parseInt(pageCount) != pageCount)
        pageCount++;

    if (pageCount <= 5)
        index = 1;

    if (pageCount == 1)
        return pageHtml;

    if (pageIndex > 1)
        pageHtml += '<a href="' + loc + '?startIndex=' + perv + '" title="">Prev</a>';

    for (var i = index; i <= pageCount; i++) {
        count++;
        if (i == pageIndex) {
            pageHtml += '<a href="' + location + '" title="" class="current">' + i + '</a>';
        }
        else {
            pageHtml += '<a href="' + loc + '?startIndex=' + i + '" title="" >' + i + '</a>';
        }

        if (count > 5) {
            pageHtml += '<span>...</span>';
            pageHtml += '<a href="' + loc + '?startIndex=' + pageCount + '" title="">' + pageCount + '</a>';
            break;
        }
    }

    if (pageIndex + 1 < pageCount)
        pageHtml += '<a href="' + loc + '?startIndex=' + next + '" title="">Next</a></div>'

    return pageHtml;
}

function utcToDate(utcCurrTime) {
    utcCurrTime = utcCurrTime + "";
    var date = "";
    var month = new Array();
    month["Jan"] = 1;
    month["Feb"] = 2;
    month["Mar"] = 3;
    month["Apr"] = 4;
    month["May"] = 5;
    month["Jun"] = 6;
    month["Jul"] = 7;
    month["Aug"] = 8;
    month["Sep"] = 9;
    month["Oct"] = 10;
    month["Nov"] = 11;
    month["Dec"] = 12;
    var week = new Array();
    week["Mon"] = "一";
    week["Tue"] = "二";
    week["Wed"] = "三";
    week["Thu"] = "四";
    week["Fri"] = "五";
    week["Sat"] = "六";
    week["Sun"] = "日";

    str = utcCurrTime.split(" ");
    date = str[5] + "-";
    date = date + month[str[1]] + "-" + str[2] + "-" + str[3];
    return date;
}

function SetHeaderAndFooter() {
    $(document).ready(function () {
        $.get("header.html", function (data) {
            $("#divHeader").html(data);
        });

        $.get("footer.html", function (data) {
            $("#divFooter").html(data);
        });
    });
}